package com.fingard.dsp.bank.directbank.nbcb01;

import java.math.BigDecimal;
import java.util.Date;

import com.fingard.constant.Format;
import com.fingard.dsp.bank.directbank.bankInterface.IElecBillTrans;
import com.fingard.dsp.bank.reqrespobj.elecbilltrans.*;
import com.fingard.dsp.bank.reqrespobj.elecbilltrans.detail.*;
import com.fingard.text.StringHelper;
import com.fingard.xml.XElement;
import com.fingard.xml.XmlTextReader;
import com.fingard.xml.XmlTextWriter;

/**
 * Created by F on 2018/11/12.
 * 宁波银行电票操作接口类
 */
public class NBCB01ElecBillTrans extends NBCB01Base implements IElecBillTrans {
    /**
     * 通用签收 b2e0109
     */
    @Override
    public RetAtsB003BillRespSubmit D_B003_BillResp_Submit(ReqB003BillRespSubmit query) throws Exception{
        RetAtsB003BillRespSubmit retAts = new RetAtsB003BillRespSubmit(query.reqHeader);
        RetAtsB003BillRespSubmitDetail detail=new RetAtsB003BillRespSubmitDetail();
        retAts.writeBeforeDetail();
        //赋值通用参数
        serviceId = "srv3099_commonSignRec";
        XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象
        //写入通用的头部节点
        writeCommonHeader(xmlWriter);
        if(!"".equals(bankFront.token)) {
            while (query.readRecord()) {
                //业务类型
                String eBillBusessType = getBillTypeIsB003(query.detail.respType, query.detail.proPayType);
                //先根据票据号码查询票据详细信息
                XElement tmpBkReader = getBillInfoByOwn(query.detail.actNum, query.detail.billType, query.detail.billNo, eBillBusessType,"2");
                if (tmpBkReader != null) {
                    xmlWriter.writeElementString("functionId", "srv3099");
                    xmlWriter.writeElementString("functionName", "签收通用提交");
                    //请求报文体
                    xmlWriter.writeStartElement("opReq");
                    xmlWriter.writeElementString("serialNo", query.detail.reqSeqID);//交易序列号
                    xmlWriter.writeElementString("reqTime", Format.Date8Format.format(new Date()));//客户端请求时间
                    xmlWriter.writeStartElement("ReqParam");
                    xmlWriter.writeElementString("KHHM", getBankConfig().getValueAsString("customerID"));//客户号码"9000016229"、bankFront.loginName
                    xmlWriter.writeElementString("YWDM", "031");//业务代码
                    xmlWriter.writeElementString("PJJE", query.detail.billAmt);//票据金额
                    xmlWriter.writeElementString("PJZT", tmpBkReader.getSingleText("PJZT"));//票据状态
                    xmlWriter.writeElementString("PJHM", query.detail.billNo);//票据号码
                    xmlWriter.writeElementString("PJLX", getBillTypeToBank(query.detail.billType));//票据类型
                    xmlWriter.writeElementString("BWBZH",tmpBkReader.getSingleText("BWBSH"));//报文标识号
                    xmlWriter.writeElementString("BWSJ", tmpBkReader.getSingleText("BWSJ"));//报文时间
                    //应答类型 1-承兑应答 2-收票应答 3-背书转让应答 4-回购式贴现赎回应答 5-质押解除应答 6-提示付款应答 7-保证应答 8-同意清偿应,9-质押签收
                    String cxlx="";
                    switch (Integer.parseInt(query.detail.respType)){
                        case 1:cxlx="B3";break;//承兑签收
                        case 2:cxlx="A1";break;//收票签收
                        case 3:cxlx="A2";break;//背书签收
                        case 9:cxlx="A6";break;//质押签收
                        case 5:cxlx="A7";break;//质押解除签收
                        default:
                            detail.respCode = "-1";
                            detail.respInfo = "暂不支持此签收类型";
                            retAts.writeDetail(detail);
                            retAts.writeEnd();
                            return retAts;
                    }
                    xmlWriter.writeElementString("CXLX", cxlx);//查询类型
                    xmlWriter.writeElementString("CXMC", "");//查询人名称
                    xmlWriter.writeElementString("CXZH", "");//查询账号
                    xmlWriter.writeElementString("CPRZH", tmpBkReader.getSingleText("CPRZH"));//出票人账号
                    xmlWriter.writeElementString("CPRMC", tmpBkReader.getSingleText("CPRMC"));//出票人名称
                    xmlWriter.writeElementString("CPRLB", tmpBkReader.getSingleText("CPRLB"));//出票人类别
                    xmlWriter.writeElementString("CPRHH", tmpBkReader.getSingleText("CPRHH"));//出票人行号
                    xmlWriter.writeElementString("CPRHMC", tmpBkReader.getSingleText("CPRHM"));//出票人开户行名称
                    xmlWriter.writeElementString("RZHMC", "");//入账行名
                    xmlWriter.writeElementString("FQRMC", tmpBkReader.getSingleText("FQRMC"));//发起人名称
                    xmlWriter.writeElementString("FQRZH", tmpBkReader.getSingleText("FQRZH"));//发起人账号
                    xmlWriter.writeElementString("FQRHH", tmpBkReader.getSingleText("FQRHH"));//发起人行号
                    xmlWriter.writeElementString("CDRHM", tmpBkReader.getSingleText("CDRHM"));//承兑人行名
                    xmlWriter.writeElementString("CDRHH", tmpBkReader.getSingleText("CDRHH"));//承兑人行号
                    xmlWriter.writeElementString("CDRMC", tmpBkReader.getSingleText("CDRMC"));//承兑人名称
                    String cdrzh=tmpBkReader.getSingleText("CDRZH");
                    if(StringHelper.isNullOrEmpty(cdrzh)){
                        cdrzh="0";
                    }
                    xmlWriter.writeElementString("CDRZH", cdrzh);//承兑人账号
                    xmlWriter.writeElementString("CPRQ", tmpBkReader.getSingleText("CPRQ"));//出票起日
                    xmlWriter.writeElementString("CPZQ", tmpBkReader.getSingleText("DQR"));//出票止日
                    xmlWriter.writeElementString("JFDM", "");//拒付代码
                    xmlWriter.writeElementString("SPRZH", tmpBkReader.getSingleText("SPRZH"));//收票人账号
                    xmlWriter.writeElementString("SPRMC", tmpBkReader.getSingleText("SPRMC"));//收票人名称
                    xmlWriter.writeElementString("SPRHM", tmpBkReader.getSingleText("SPRHM"));//收票人行名
                    xmlWriter.writeElementString("SPRHH", tmpBkReader.getSingleText("SPRHH"));//收票人行号
                    xmlWriter.writeElementString("HFBJ", "1".equals(query.detail.respFlag)?"SU00":"SU01");//回复标记
                    xmlWriter.writeElementString("ZRBJ", tmpBkReader.getSingleText("ZRBJ"));//不得转让标记
                    xmlWriter.writeEndElement();
                    xmlWriter.writeEndElement();
                    String signXml = getDataSignData(xmlWriter);
                    if (signnatrue(signXml) == true) {
                        xmlWriter.writeElementString("signData", signature);//签名数据
                        xmlWriter.writeEndDocument();
                        String[] tmpStrRet = sendToBank(getDataSendBank(xmlWriter.toXmlString()));//发送银行

                        if (tmpStrRet[0].length() == 0) {
                            StringBuilder tmpSbMsg = new StringBuilder();
                            XmlTextReader tmpBkReader2 = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                            if (tmpBkReader2 != null) {
                                String respCode = tmpBkReader2.getFirstText("/NBCBEBankData/retCode");
                                String respInfo = tmpBkReader2.getFirstText("/NBCBEBankData/errorMsg");
                                if (respCode != null && isActiveRetCode(respCode)) {
                                    detail.respCode = "0";
                                    detail.respInfo = tmpBkReader2.getFirstText("/NBCBEBankData/opRep/opResult/SBYY");
                                    detail.reqSeqID = query.detail.reqSeqID;
                                    detail.payInfoCode = tmpBkReader2.getFirstText("/NBCBEBankData/opRep/opResult/JYZT");
                                    detail.transState = detail.payInfoCode;
                                }else {
                                    detail.respCode = "0";
                                    detail.respInfo = respCode+"："+respInfo;
                                    detail.reqSeqID = query.detail.reqSeqID;
                                    detail.payInfoCode = "91";//银行确认 返回非0000或非000000时，可以判定交易失败
                                    detail.transState = detail.payInfoCode;
                                }
                            } else {
                                detail.respCode = "-1";
                                detail.respInfo = tmpSbMsg.toString();
                            }
                        } else {
                            detail.respCode = "-1";
                            detail.respInfo = tmpStrRet[1];
                        }
                    }else {
                        detail.respCode = "-1";
                        detail.respInfo = tmpSign[1];
                    }
                }else {
                    detail.respCode = "-1";
                    detail.respInfo = "查询票据详情失败";
                }
            }
        }else {
            detail.respCode = "-1";
            detail.respInfo = "登录失败";
        }
        retAts.writeDetail(detail);
        retAts.writeEnd();
        return retAts;
    }

    /**
     * 出票 b2e0101

     */
    @Override
    public RetAtsB101BillApplySubmit D_B101_BillResp_Submit(ReqB101BillApplySubmit query) throws Exception{
        RetAtsB101BillApplySubmit retAts=new RetAtsB101BillApplySubmit(query.reqHeader);
        RetAtsB101BillApplySubmitDetail detail;
        retAts.writeBeforeDetail();
        query.readRecord();
        try {
            if ("1".equals(query.detail.billType)) {//银承
                detail = b101BillRespSubitOne(query);
            } else {//商承
                detail = b101BillRespSubitTwo(query);
            }
        }catch (Exception ex){
            ex.printStackTrace();
            detail = new RetAtsB101BillApplySubmitDetail();
            detail.respCode = "-1";
            detail.respInfo = ex.getMessage();
        }
        retAts.writeDetail(detail);
        retAts.writeEnd();
        return retAts;
    }

    /**
    * 提示承兑 b2e0105

     * */
    @Override
    public RetAtsB102BillAccpSubmit D_B102_BillResp_Submit(ReqB102BillAccpSubmit query) throws Exception{
        RetAtsB102BillAccpSubmit retAts=new RetAtsB102BillAccpSubmit(query.reqHeader);
        RetAtsB102BillAccpSubmitDetail detail;
        retAts.writeBeforeDetail();
        query.readRecord();
        try {
            if ("1".equals(query.detail.billType)) {//银承
                detail = b102BillRespSubitOne(query);
            } else {//商承
                detail = b102BillRespSubitTwo(query);
            }
        }catch (Exception ex){
            ex.printStackTrace();
            detail = new RetAtsB102BillAccpSubmitDetail();
            detail.respCode = "-1";
            detail.respInfo = ex.getMessage();
        }
        retAts.writeDetail(detail);
        retAts.writeEnd();
        return retAts;
    }

    /**
     * 撤票 b2e0104

     */
    @Override
    public RetAtsB103BillRetSubmit D_B103_BillResp_Submit(ReqB103BillRetSubmit query) throws Exception{
        RetAtsB103BillRetSubmit retAts = new RetAtsB103BillRetSubmit(query.reqHeader);
        RetAtsB103BillRetSubmitDetail detail=new RetAtsB103BillRetSubmitDetail();
        retAts.writeBeforeDetail();
        query.readRecord();
        //赋值通用参数
        serviceId = "srv165_submitIssueDraftCancel";
        XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象
        //写入通用的头部节点
        writeCommonHeader(xmlWriter);
        if(!"".equals(bankFront.token)) {
                //先根据票据号码查询票据详细信息
                XElement billInfo = getBillInfoByOpen(query.detail.actNum,query.detail.billType,query.detail.billNo,"4");
                if( billInfo!=null){
                    xmlWriter.writeElementString("functionId", "srv165");
                    xmlWriter.writeElementString("functionName", "未用退回");
                    //请求报文体
                    xmlWriter.writeStartElement("opReq");
                    xmlWriter.writeElementString("serialNo", getQryTransID());//交易序列号
                    xmlWriter.writeElementString("reqTime", Format.Date8Format.format(new Date()));//客户端请求时间
                    xmlWriter.writeStartElement("ReqParam");
                    xmlWriter.writeElementString("KHHM", getBankConfig().getValueAsString("customerID"));//客户号码
                    xmlWriter.writeElementString("PJZL", getBillTypeToBank(query.detail.billType));//票据类型
                    xmlWriter.writeElementString("PJHM", query.detail.billNo);//票据号码
                    xmlWriter.writeElementString("PJJE", query.detail.billAmt);//票据金额
                    xmlWriter.writeElementString("PJZT", "");//票据状态
                    xmlWriter.writeElementString("CPRQ", billInfo.getSingleText("CPRQ"));//出票日期
                    xmlWriter.writeElementString("DQR", billInfo.getSingleText("DQR"));//到期日
                    xmlWriter.writeElementString("JYLB", "");//交易类别
                    xmlWriter.writeElementString("CPRLB", billInfo.getSingleText("CPRLB"));//发起人类别
                    xmlWriter.writeElementString("CPRMC", billInfo.getSingleText("CPRMC"));//出票人名称
                    xmlWriter.writeElementString("CPRZH", billInfo.getSingleText("CPRZH"));//出票人账号
                    xmlWriter.writeElementString("CPRHH",billInfo.getSingleText("CPRHH"));//出票人行号
                    xmlWriter.writeElementString("CPRHM", billInfo.getSingleText("CPRHM"));//出票人行名
                    xmlWriter.writeElementString("DZQM", "");//电子签名
                    xmlWriter.writeElementString("SPRMC", billInfo.getSingleText("SPRMC"));//收票人名称
                    xmlWriter.writeElementString("SPRZH", billInfo.getSingleText("SPRZH"));//收票人账号
                    xmlWriter.writeElementString("SPRHH", billInfo.getSingleText("SPRHH"));//收票人行号
                    xmlWriter.writeElementString("SPRHM", billInfo.getSingleText("SPRHM"));//收票人行名
                    xmlWriter.writeElementString("CDXY",  billInfo.getSingleText("CDXY"));//承兑协议号
                    xmlWriter.writeElementString("JYHT",  billInfo.getSingleText("JYHT"));//交易合同号
                    xmlWriter.writeElementString("FPHM",  billInfo.getSingleText("FPHM"));//发票号码
                    xmlWriter.writeElementString("CDRMC", billInfo.getSingleText("CDRMC"));//承兑人名称
                    xmlWriter.writeElementString("CDRZH", billInfo.getSingleText("CDRZH"));//承兑人帐号
                    xmlWriter.writeElementString("CDRHH", billInfo.getSingleText("CDRHH"));//承兑人行号
                    xmlWriter.writeElementString("CDRHM", billInfo.getSingleText("CDRHM"));//承兑人开户行名
                    xmlWriter.writeElementString("BZJBL", billInfo.getSingleText("BZJBL"));//保证金比率
                    xmlWriter.writeElementString("BZJBZ", billInfo.getSingleText("BZJBZ"));//保证金标志
                    xmlWriter.writeElementString("CZH", billInfo.getSingleText("CZH"));//出账号
                    xmlWriter.writeElementString("CZXH", billInfo.getSingleText("CZXH"));//出账序号
                    xmlWriter.writeElementString("ZRBJ", billInfo.getSingleText("ZRBJ"));//不得转让标志
                    xmlWriter.writeEndElement();
                    xmlWriter.writeEndElement();
                    String signXml = getDataSignData(xmlWriter);
                    if (signnatrue(signXml) == true) {
                        xmlWriter.writeElementString("signData", signature);//签名数据
                        xmlWriter.writeEndDocument();
                        String[] tmpStrRet = sendToBank(getDataSendBank(xmlWriter.toXmlString()));//发送银行

                        if (tmpStrRet[0].length() == 0) {
                            StringBuilder tmpSbMsg2 = new StringBuilder();
                            XmlTextReader tmpBkReader2 = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg2);
                            if (tmpBkReader2 != null) {
                                String respCode = tmpBkReader2.getFirstText("/NBCBEBankData/retCode");
                                String respInfo = tmpBkReader2.getFirstText("/NBCBEBankData/errorMsg");
                                if (respCode != null && isActiveRetCode(respCode)) {
                                    detail.respCode = "0";
                                    detail.respInfo = tmpBkReader2.getFirstText("/NBCBEBankData/opRep/opResult/SBYY");
                                    detail.reqSeqID = tmpBkReader2.getFirstText("/NBCBEBankData/opRep/opResult/ZLLS");
                                    detail.payInfoCode = tmpBkReader2.getFirstText("/NBCBEBankData/opRep/opResult/JYZT");
                                    detail.transState = detail.payInfoCode;
                                }else {
                                    detail.respCode = "0";
                                    detail.respInfo = respCode+"："+respInfo;
                                    detail.reqSeqID = query.detail.reqSeqID;
                                    detail.payInfoCode = "91";//银行确认 返回非0000或非000000时，可以判定交易失败
                                    detail.transState = detail.payInfoCode;
                                }
                            } else {
                                detail.respCode = "-1";
                                detail.respInfo = tmpSbMsg2.toString();
                            }
                        } else {
                            detail.respCode = "-1";
                            detail.respInfo = tmpStrRet[1].toString();
                        }
                    }else {
                        detail.respCode = "-1";
                        detail.respInfo = tmpSign[1];
                    }
                }else {
                    detail.respCode = "-1";
                    detail.respInfo = "查询票据详情失败";
                }
        }else {
            detail.respCode = "-1";
            detail.respInfo = "登录失败";
        }
        retAts.writeDetail(detail);
        retAts.writeEnd();
        return retAts;
    }

    /**
     * 提示收票 b2e0108  ok

     */
    @Override
    public RetAtsB104BillReceSubmit D_B104_BillResp_Submit(ReqB104BillReceSubmit query) throws Exception {
        RetAtsB104BillReceSubmit retAts = new RetAtsB104BillReceSubmit(query.reqHeader);
        RetAtsB104BillReceSubmitDetail detail = new RetAtsB104BillReceSubmitDetail();
        retAts.writeBeforeDetail();
        query.readRecord();
        try {
            //赋值通用参数
            serviceId = "srv3007_remindRece";
            XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象
            //写入通用的头部节点
            writeCommonHeader(xmlWriter);
            if (!"".equals(bankFront.token)) {
                //先根据票据号码查询票据详细信息
                XElement billInfo = getBillInfoByOwn(query.detail.actNum, query.detail.billType, query.detail.billNo, "1","1");
                if (billInfo != null) {
                    xmlWriter.writeElementString("functionId", "srv3007");
                    xmlWriter.writeElementString("functionName", "提示收款人收票");
                    //请求报文体
                    xmlWriter.writeStartElement("opReq");
                    xmlWriter.writeElementString("serialNo", query.detail.reqSeqID);//交易序列号
                    xmlWriter.writeElementString("reqTime", Format.Date8Format.format(new Date()));//客户端请求时间
                    xmlWriter.writeStartElement("ReqParam");
                    xmlWriter.writeElementString("PJZL", getBillTypeToBank(query.detail.billType));//票据类型
                    xmlWriter.writeElementString("KHHM", getBankConfig().getValueAsString("customerID"));//客户号码
                    xmlWriter.writeElementString("PJHM", query.detail.billNo);//票据号码
                    xmlWriter.writeElementString("PJJE", query.detail.billAmt);//票据金额
                    xmlWriter.writeElementString("DZQM", "");//电子签名
                    xmlWriter.writeElementString("CPRQ", billInfo.getSingleText("CPRQ"));//出票日期
                    xmlWriter.writeElementString("DQR", billInfo.getSingleText("DQR"));//到期日
                    xmlWriter.writeElementString("ZRBJ", billInfo.getSingleText("ZRBJ"));//不得转让标志
                    xmlWriter.writeElementString("PJZT", billInfo.getSingleText("ZRBJ"));//票据状态
                    xmlWriter.writeElementString("CPRLB", billInfo.getSingleText("CPRLB"));//出票人类别
                    xmlWriter.writeElementString("JYLB", billInfo.getSingleText("JYLB"));//交易类别
                    xmlWriter.writeElementString("CPRMC", billInfo.getSingleText("CPRMC"));//出票人名称
                    xmlWriter.writeElementString("CPRZH", billInfo.getSingleText("CPRZH"));//出票人账号
                    xmlWriter.writeElementString("CPRHH", billInfo.getSingleText("CPRHH"));//出票人行号
                    xmlWriter.writeElementString("CPRHM", billInfo.getSingleText("CPRHM"));//出票人行名
                    xmlWriter.writeElementString("SPRMC", billInfo.getSingleText("SPRMC"));//收票人名称
                    xmlWriter.writeElementString("SPRZH", billInfo.getSingleText("SPRZH"));//收票人账号
                    xmlWriter.writeElementString("SPRHH", billInfo.getSingleText("SPRHH"));//收票人行号
                    xmlWriter.writeElementString("SPRHM", billInfo.getSingleText("SPRHM"));//收票人行名
                    xmlWriter.writeElementString("CDXY", billInfo.getSingleText("CDXY"));//承兑协议号
                    xmlWriter.writeElementString("JYHT", billInfo.getSingleText("JYHT"));//交易合同号
                    xmlWriter.writeElementString("FPHM", billInfo.getSingleText("FPHM"));//发票号码
                    xmlWriter.writeElementString("CDRMC", billInfo.getSingleText("CDRMC"));//承兑人名称
                    String cdrzh=billInfo.getSingleText("CDRZH");
                    if(StringHelper.isNullOrEmpty(cdrzh)){
                        cdrzh="0";
                    }
                    xmlWriter.writeElementString("CDRZH", cdrzh);//承兑人账号
                    xmlWriter.writeElementString("BZJBL", billInfo.getSingleText("BZJBL"));//保证金比例
                    xmlWriter.writeElementString("CDRHH", billInfo.getSingleText("CDRHH"));//承兑人行号
                    xmlWriter.writeElementString("CDRHM", billInfo.getSingleText("CDRHM"));//承兑人开户行名
                    xmlWriter.writeElementString("BZJBZ", billInfo.getSingleText("BZJBZ"));//保证金币种
                    xmlWriter.writeElementString("CHPRLB", billInfo.getSingleText("CHPRLB"));//持票人类别
                    xmlWriter.writeElementString("CHPRJGDM", billInfo.getSingleText("CHPRJGDM"));//持票人组织机构代码
                    xmlWriter.writeElementString("CHPRMC", billInfo.getSingleText("CHPRMC"));//持票人名称
                    xmlWriter.writeElementString("CHPRZH", billInfo.getSingleText("CHPRZH"));//持票人账号
                    xmlWriter.writeElementString("CHPRHH", billInfo.getSingleText("CHPRHH"));//持票人行号
                    xmlWriter.writeElementString("CHPRHM", billInfo.getSingleText("CHPRHM"));//持票人行名
                    xmlWriter.writeEndElement();
                    xmlWriter.writeEndElement();
                    String signXml = getDataSignData(xmlWriter);
                    if (signnatrue(signXml) == true) {
                        xmlWriter.writeElementString("signData", signature);//签名数据
                        xmlWriter.writeEndDocument();
                        String[] tmpStrRet = sendToBank(getDataSendBank(xmlWriter.toXmlString()));//发送银行
                        if (tmpStrRet[0].length() == 0) {
                            StringBuilder tmpSbMsg2 = new StringBuilder();
                            XmlTextReader tmpBkReader2 = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg2);
                            if (tmpBkReader2 != null) {
                                String respCode = tmpBkReader2.getFirstText("/NBCBEBankData/retCode");
                                String respInfo = tmpBkReader2.getFirstText("/NBCBEBankData/errorMsg");
                                if (respCode != null && isActiveRetCode(respCode)) {
                                    detail.respCode = "0";
                                    detail.respInfo = tmpBkReader2.getFirstText("/NBCBEBankData/opRep/opResult/SBYY");
                                    detail.reqSeqID = query.detail.reqSeqID;
                                    detail.payInfoCode = tmpBkReader2.getFirstText("/NBCBEBankData/opRep/opResult/JYZT");
                                    detail.transState = detail.payInfoCode;
                                } else {
                                    detail.respCode = "0";
                                    detail.respInfo = respCode+"："+respInfo;
                                    detail.reqSeqID = query.detail.reqSeqID;
                                    detail.payInfoCode = "91";//银行确认 返回非0000或非000000时，可以判定交易失败
                                    detail.transState = detail.payInfoCode;
                                }
                            } else {
                                detail.respCode = "-1";
                                detail.respInfo = tmpSbMsg2.toString();
                            }
                        } else {
                            detail.respCode = "-1";
                            detail.respInfo = tmpStrRet[1];
                        }
                    } else {
                        detail.respCode = "-1";
                        detail.respInfo = tmpSign[1];
                    }
                } else {
                    detail.respCode = "-1";
                    detail.respInfo = "查询票据详情失败";
                }
            }else{
                detail.respCode = "-1";
                detail.respInfo = "登录失败";
            }
        }catch (Exception ex){
            ex.printStackTrace();
            detail.respCode = "-1";
            detail.respInfo = ex.getMessage();
        }
        retAts.writeDetail(detail);
        retAts.writeEnd();
        return retAts;
    }

    /**
     * 背书转让申请 b2e0280 ok
     */
    @Override
    public RetAtsB105BillEndoSubmit D_B105_BillResp_Submit(ReqB105BillEndoSubmit query) throws Exception{
        RetAtsB105BillEndoSubmit retAts = new RetAtsB105BillEndoSubmit(query.reqHeader);
        RetAtsB105BillEndoSubmitDetail detail=new RetAtsB105BillEndoSubmitDetail();
        retAts.writeBeforeDetail();
        query.readRecord();
        try {
            //赋值通用参数
            serviceId = "srv3010_transferApply";
            XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象
            //写入通用的头部节点
            writeCommonHeader(xmlWriter);
            if (!"".equals(bankFront.token)) {
                //先根据票据号码查询票据详细信息
                XElement billInfo = getBillInfoByOwn(query.detail.actNum, query.detail.billType, query.detail.billNo, "2","1");
                if (billInfo != null) {
                    xmlWriter.writeElementString("functionId", "srv3010");
                    xmlWriter.writeElementString("functionName", "背书转让申请");
                    //请求报文体
                    xmlWriter.writeStartElement("opReq");
                    xmlWriter.writeElementString("serialNo", query.detail.reqSeqID);//交易序列号
                    xmlWriter.writeElementString("reqTime", Format.Date8Format.format(new Date()));//客户端请求时间
                    xmlWriter.writeStartElement("ReqParam");
                    xmlWriter.writeElementString("PJZL", getBillTypeToBank(query.detail.billType));//票据类型
                    xmlWriter.writeElementString("KHHM", getBankConfig().getValueAsString("customerID"));//客户号码bankFront.loginName
                    xmlWriter.writeElementString("PJHM", query.detail.billNo);//票据号码
                    xmlWriter.writeElementString("PJJE", query.detail.billAmt);//票据金额
                    xmlWriter.writeElementString("PJZT", billInfo.getSingleText("PJZT"));//票据状态
                    xmlWriter.writeElementString("CPRQ", billInfo.getSingleText("CPRQ"));//出票日期
                    xmlWriter.writeElementString("DQR", billInfo.getSingleText("DQR"));//到期日
                    xmlWriter.writeElementString("ZRBJ", getBankConfig().getMapValueByKey("transFlagMapping", query.detail.transFlag));//不得转让标志
                    xmlWriter.writeElementString("JYLB", billInfo.getSingleText("JYLB"));//交易类别
                    xmlWriter.writeElementString("CPRLB", billInfo.getSingleText("CPRLB"));//发起人类别
                    xmlWriter.writeElementString("CPRMC", billInfo.getSingleText("CPRMC"));//出票人名称
                    xmlWriter.writeElementString("CPRZH", billInfo.getSingleText("CPRZH"));//出票人账号
                    xmlWriter.writeElementString("CPRHH", billInfo.getSingleText("CPRHH"));//出票人行号
                    xmlWriter.writeElementString("CPRHM", billInfo.getSingleText("CPRHM"));//出票人行名
                    xmlWriter.writeElementString("SPRMC", billInfo.getSingleText("SPRMC"));//收票人名称
                    xmlWriter.writeElementString("SPRZH", billInfo.getSingleText("SPRZH"));//收票人账号
                    xmlWriter.writeElementString("SPRHH", billInfo.getSingleText("SPRHH"));//收票人行号
                    xmlWriter.writeElementString("SPRHM", billInfo.getSingleText("SPRHM"));//收票人行名
                    String cdrzh=billInfo.getSingleText("CDRZH");
                    if(StringHelper.isNullOrEmpty(cdrzh)){
                        cdrzh="0";
                    }
                    xmlWriter.writeElementString("CDRZH", cdrzh);//承兑人账号
                    xmlWriter.writeElementString("CDRMC", billInfo.getSingleText("CDRMC"));//承兑人名称
                    xmlWriter.writeElementString("CDRHM", billInfo.getSingleText("CDRHM"));//承兑人行名
                    xmlWriter.writeElementString("CDRHH", billInfo.getSingleText("CDRHH"));//承兑人行号
                    xmlWriter.writeElementString("BZJBL", billInfo.getSingleText("BZJBL"));//保证金比率
                    xmlWriter.writeElementString("BZJBZ", billInfo.getSingleText("BZJBZ"));//保证金币种
                    xmlWriter.writeElementString("CHPRZH", billInfo.getSingleText("CHPRZH"));//持票人账号
                    xmlWriter.writeElementString("CHPRMC", billInfo.getSingleText("CHPRMC"));//持票人名称
                    xmlWriter.writeElementString("CHPRHM", billInfo.getSingleText("CHPRHM"));//持票人行名
                    xmlWriter.writeElementString("CHPRHH", billInfo.getSingleText("CHPRHH"));//持票人行号
                    xmlWriter.writeElementString("CHPRLB", billInfo.getSingleText("CHPRLB"));//持票人类别
                    xmlWriter.writeElementString("CHPRJGDM", billInfo.getSingleText("CHPRJGDM"));//持票人组织机构代码
                    xmlWriter.writeElementString("BBSRZH", query.detail.receAct);//被背书人账号
                    xmlWriter.writeElementString("BBSRMC", query.detail.receName);//被背书人名称
                    xmlWriter.writeElementString("BBSRHH", query.detail.receBnkCode);//被背书人行号
                    xmlWriter.writeElementString("BBSRHM", query.detail.receBnkName);//被背书人行名
                    xmlWriter.writeEndElement();
                    xmlWriter.writeEndElement();
                    String signXml = getDataSignData(xmlWriter);
                    if (signnatrue(signXml) == true) {
                        xmlWriter.writeElementString("signData", signature);//签名数据
                        xmlWriter.writeEndDocument();
                        String[] tmpStrRet = sendToBank(getDataSendBank(xmlWriter.toXmlString()));//发送银行

                        if (tmpStrRet[0].length() == 0) {
                            StringBuilder tmpSbMsg2 = new StringBuilder();
                            XmlTextReader tmpBkReader2 = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg2);
                            if (tmpBkReader2 != null) {
                                String respCode = tmpBkReader2.getFirstText("/NBCBEBankData/retCode");
                                String respInfo = tmpBkReader2.getFirstText("/NBCBEBankData/errorMsg");
                                if (respCode != null && isActiveRetCode(respCode)) {
                                    detail.respCode = "0";
                                    detail.respInfo = tmpBkReader2.getFirstText("/NBCBEBankData/opRep/opResult/SBYY");
                                    detail.reqSeqID = query.detail.reqSeqID;
                                    detail.payInfoCode = tmpBkReader2.getFirstText("/NBCBEBankData/opRep/opResult/JYZT");
                                    detail.transState = detail.payInfoCode;
                                } else {
                                    detail.respCode = "0";
                                    detail.respInfo = respCode+"："+respInfo;
                                    detail.reqSeqID = query.detail.reqSeqID;
                                    detail.payInfoCode = "91";//银行确认 返回非0000或非000000时，可以判定交易失败
                                    detail.transState = detail.payInfoCode;
                                }
                            } else {
                                detail.respCode = "-1";
                                detail.respInfo = tmpSbMsg2.toString();
                            }
                        } else {
                            detail.respCode = "-1";
                            detail.respInfo = tmpStrRet[1];
                        }
                    } else {
                        detail.respCode = "-1";
                        detail.respInfo = tmpSign[1];
                    }
                } else {
                    detail.respCode = "-1";
                    detail.respInfo = "查询票据详情失败";
                }
            } else {
                detail.respCode = "-1";
                detail.respInfo = "登录失败";
            }
        }catch (Exception ex){
            ex.printStackTrace();
            detail.respCode = "-1";
            detail.respInfo = ex.getMessage();
        }
        retAts.writeDetail(detail);
        retAts.writeEnd();
        return retAts;
    }

    /**
     * 贴现申请 b2e0110 不支持

     */
    @Override
    public RetAtsB106BillDiscSubmit D_B106_BillResp_Submit(ReqB106BillDiscSubmit query) throws Exception{
        RetAtsB106BillDiscSubmit retAts=new RetAtsB106BillDiscSubmit(query.reqHeader);
        retAts.writeBeforeDetail();
        RetAtsB106BillDiscSubmitDetail detail=new RetAtsB106BillDiscSubmitDetail();
        detail.respCode="-1";
        detail.respInfo="银行暂不支持此操作";
        retAts.writeDetail(detail);
        retAts.writeEnd();
        return retAts;
    }

    /**
     * 质押申请 b2e0285 不支持

     */
    @Override
    public RetAtsB107BillPledSubmit D_B107_BillResp_Submit(ReqB107BillPledSubmit query) throws Exception{
        RetAtsB107BillPledSubmit retAts=new RetAtsB107BillPledSubmit(query.reqHeader);
        retAts.writeBeforeDetail();
        RetAtsB107BillPledSubmitDetail detail=new RetAtsB107BillPledSubmitDetail();
        detail.respCode="-1";
        detail.respInfo="银行暂不支持此操作";
        retAts.writeDetail(detail);
        retAts.writeEnd();
        return retAts;
    }

    /**
     * 提示付款 b2e0111 ok

     */
    @Override
    public RetAtsB108BillPaySubmit D_B108_BillResp_Submit(ReqB108BillPaySubmit query) throws Exception{
        RetAtsB108BillPaySubmit retAts = new RetAtsB108BillPaySubmit(query.reqHeader);
        RetAtsB108BillPaySubmitDetail detail=new RetAtsB108BillPaySubmitDetail();
        retAts.writeBeforeDetail();
        //赋值通用参数
        serviceId = "srv3016_submitCollectingApply";
        XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象
        //写入通用的头部节点
        writeCommonHeader(xmlWriter);
        if(!"".equals(bankFront.token)) {
            while (query.readRecord()) {
                //先根据票据号码查询票据详细信息
                XElement billInfo = getBillInfoByOwn(query.detail.actNum,query.detail.billType,query.detail.billNo,"1".equals(query.detail.proPayType)?"8":"9","1");
                if( billInfo!=null){
                    xmlWriter.writeElementString("functionId", "srv3016");
                    xmlWriter.writeElementString("functionName", "提示付款申请");
                    //请求报文体
                    xmlWriter.writeStartElement("opReq");
                    xmlWriter.writeElementString("serialNo", query.detail.reqSeqID);//交易序列号
                    xmlWriter.writeElementString("reqTime", Format.Date8Format.format(new Date()));//客户端请求时间
                    xmlWriter.writeStartElement("ReqParam");
                    xmlWriter.writeElementString("KHHM", getBankConfig().getValueAsString("customerID"));//客户号码
                    xmlWriter.writeElementString("PJLX", getBillTypeToBank(query.detail.billType));//票据类型
                    xmlWriter.writeElementString("QSBJ", "1".equals(query.detail.payType)?"SM00":("2".equals(query.detail.payType)?"SM01":""));//清算类型
                    xmlWriter.writeElementString("PJHM", query.detail.billNo);//票据号码
                    xmlWriter.writeElementString("PJJE", query.detail.billAmt);//票据金额
                    xmlWriter.writeElementString("CPRQ", billInfo.getSingleText("CPRQ"));//出票日期
                    xmlWriter.writeElementString("DQR", billInfo.getSingleText("DQR"));//到期日
                    xmlWriter.writeElementString("JYLB", billInfo.getSingleText("JYLB"));//交易类别
                    xmlWriter.writeElementString("CPRLB", billInfo.getSingleText("CPRLB"));//发起人类别
                    xmlWriter.writeElementString("CPRZH", billInfo.getSingleText("CPRZH"));//出票人账号
                    xmlWriter.writeElementString("CPRMC", billInfo.getSingleText("CPRMC"));//出票人名称
                    xmlWriter.writeElementString("CPRHH", billInfo.getSingleText("CPRHH"));//出票人行号
                    xmlWriter.writeElementString("CPRHM", billInfo.getSingleText("CPRHM"));//出票人行名
                    xmlWriter.writeElementString("CPRLB", billInfo.getSingleText("CPRLB"));//出票人类别
                    xmlWriter.writeElementString("SPRZH", billInfo.getSingleText("SPRZH"));//收票人账号
                    xmlWriter.writeElementString("SPRMC", billInfo.getSingleText("SPRMC"));//收票人名称
                    xmlWriter.writeElementString("SPRHH", billInfo.getSingleText("SPRHH"));//收票人行号
                    xmlWriter.writeElementString("SPRHM", billInfo.getSingleText("SPRHM"));//收票人行名
                    xmlWriter.writeElementString("CDXY", billInfo.getSingleText("CDXY"));//承兑协议号
                    xmlWriter.writeElementString("CDRMC", billInfo.getSingleText("CDRMC"));//承兑人名称
                    String cdrzh=billInfo.getSingleText("CDRZH");
                    if(StringHelper.isNullOrEmpty(cdrzh)){
                        cdrzh="0";
                    }
                    xmlWriter.writeElementString("CDRZH", cdrzh);//承兑人账号
                    xmlWriter.writeElementString("CDRHM", billInfo.getSingleText("CDRHM"));//承兑人行名
                    xmlWriter.writeElementString("CDRHH", billInfo.getSingleText("CDRHH"));//承兑人行号
                    xmlWriter.writeElementClosed("BZJBZ");//保证金币种
                    xmlWriter.writeElementString("CHPRLB",  billInfo.getSingleText("CHPRLB"));//持票人类别
                    xmlWriter.writeElementString("CHPRJGDM",billInfo.getSingleText("CHPRJGDM"));//持票人组织机构代码
                    xmlWriter.writeElementString("CHPRZH",  billInfo.getSingleText("CHPRZH"));//持票人账号
                    xmlWriter.writeElementString("CHPRMC",  billInfo.getSingleText("CHPRMC"));//持票人名称
                    xmlWriter.writeElementString("CHPRHM",  billInfo.getSingleText("CHPRHM"));//持票人行名
                    xmlWriter.writeElementString("CHPRHH",  billInfo.getSingleText("CHPRHH"));//持票人行号
                    xmlWriter.writeElementString("BZJBL", billInfo.getSingleText("BZJBL"));//保证金比率
                    xmlWriter.writeElementString("ZRBJ",  billInfo.getSingleText("ZRBJ"));//不得转让标志
                    xmlWriter.writeElementString("TSFKJE", query.detail.billAmt);//提示付款金额
                    xmlWriter.writeElementString("CXTJ", "1".equals(query.detail.proPayType)?"8":("2".equals(query.detail.proPayType)?"9":""));//查询条件
                    xmlWriter.writeElementString("YQYY", "2".equals(query.detail.proPayType)?query.detail.overDueRea:"");//延期原因
                    xmlWriter.writeEndElement();
                    xmlWriter.writeEndElement();
                    String signXml = getDataSignData(xmlWriter);
                    if (signnatrue(signXml) == true) {
                        xmlWriter.writeElementString("signData", signature);//签名数据
                        xmlWriter.writeEndDocument();
                        String[] tmpStrRet = sendToBank(getDataSendBank(xmlWriter.toXmlString()));//发送银行

                        if (tmpStrRet[0].length() == 0) {
                            StringBuilder tmpSbMsg2 = new StringBuilder();
                            XmlTextReader tmpBkReader2 = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg2);
                            if (tmpBkReader2 != null) {
                                String respCode = tmpBkReader2.getFirstText("/NBCBEBankData/retCode");
                                String respInfo = tmpBkReader2.getFirstText("/NBCBEBankData/errorMsg");
                                if (respCode != null && isActiveRetCode(respCode)) {
                                    detail.respCode = "0";
                                    detail.respInfo = tmpBkReader2.getFirstText("/NBCBEBankData/opRep/opResult/SBYY");
                                    detail.reqSeqID = query.detail.reqSeqID;
                                    detail.payInfoCode = tmpBkReader2.getFirstText("/NBCBEBankData/opRep/opResult/JYZT");
                                    detail.transState = detail.payInfoCode;
                                }else {
                                    detail.respCode = "0";
                                    detail.respInfo = respCode+"："+respInfo;
                                    detail.reqSeqID = query.detail.reqSeqID;
                                    detail.payInfoCode = "91";//银行确认 返回非0000或非000000时，可以判定交易失败
                                    detail.transState = detail.payInfoCode;
                                }
                            } else {
                                detail.respCode = "-1";
                                detail.respInfo = tmpSbMsg2.toString();
                            }
                        } else {
                            detail.respCode = "-1";
                            detail.respInfo = tmpStrRet[1];
                        }
                    }else {
                        detail.respCode = "-1";
                        detail.respInfo = tmpSign[1];
                    }
                }else {
                    detail.respCode = "-1";
                    detail.respInfo = "查询票据详情失败";
                }
            }
        }else {
            detail.respCode = "-1";
            detail.respInfo = "登录失败";
        }
        retAts.writeDetail(detail);
        retAts.writeEnd();
        return retAts;
    }

    /**
     * 保证申请  b2e0281 不支持

     */
    @Override
    public RetAtsB109BillGuarSubmit D_B109_BillResp_Submit(ReqB109BillGuarSubmit query) throws Exception{
        RetAtsB109BillGuarSubmit retAts=new RetAtsB109BillGuarSubmit(query.reqHeader);
        retAts.writeBeforeDetail();
        RetAtsB109BillGuarSubmitDetail detail=new RetAtsB109BillGuarSubmitDetail();
        detail.respCode="-1";
        detail.respInfo="银行暂不支持此操作";
        retAts.writeDetail(detail);
        retAts.writeEnd();
        return retAts;
    }

    /**
     * 追索通知 b2e0282 不支持

     */
    @Override
    public RetAtsB110BillRecoSubmit D_B110_BillResp_Submit(ReqB110BillRecoSubmit query) throws Exception{
        RetAtsB110BillRecoSubmit retAts=new RetAtsB110BillRecoSubmit(query.reqHeader);
        retAts.writeBeforeDetail();
        RetAtsB110BillRecoSubmitDetail detail=new RetAtsB110BillRecoSubmitDetail();
        detail.respCode="-1";
        detail.respInfo="银行暂不支持此操作";
        retAts.writeDetail(detail);
        retAts.writeEnd();
        return retAts;
    }

    /**
     * 同意清偿 b2e0112 不支持

     */
    @Override
    public RetAtsB111BillAgreeSubmit D_B111_BillResp_Submit(ReqB111BillAgreeSubmit query) throws Exception{
        RetAtsB111BillAgreeSubmit retAts=new RetAtsB111BillAgreeSubmit(query.reqHeader);
        retAts.writeBeforeDetail();
        RetAtsB111BillAgreeSubmitDetail detail=new RetAtsB111BillAgreeSubmitDetail();
        detail.respCode="-1";
        detail.respInfo="银行暂不支持此操作";
        retAts.writeDetail(detail);
        retAts.writeEnd();
        return retAts;
    }

    /**
     * 交易撤回 b2e0106

     */
    @Override
    public RetAtsB112BillCancSubmit D_B112_BillResp_Submit(ReqB112BillCancSubmit query) throws Exception{
        RetAtsB112BillCancSubmit retAts=new RetAtsB112BillCancSubmit(query.reqHeader);
        RetAtsB112BillCancSubmitDetail detail=new RetAtsB112BillCancSubmitDetail();
        retAts.writeBeforeDetail();
        try{
            while (query.readRecord()) {
                if ("2".equals(query.detail.cancelType)) {
                    detail=b112BillRespSubmitOne(query);//2-提示收票申请撤回
                } else if ("3".equals(query.detail.cancelType)) {
                    detail=b112BillRespSubmitTwo(query);//3-背书转让申请撤回
                }else if ("6".equals(query.detail.cancelType)){
                    detail=b112BillRespSubmitThree(query);//6-提示付款撤回
                }else {
                    detail.respCode="-1";
                    detail.respInfo="暂不支持此撤回操作";
                }
            }
        }catch (Exception ex ){
            detail.respCode="-1";
            detail.respInfo="查询异常";
            ex.printStackTrace();
            WriteBankLogLn("查询异常:"+ex);
        }
        retAts.writeDetail(detail);
        retAts.writeEnd();
        return retAts;
    }

    @Override
    public RetAtsB113ProtocolSubmit D_B113_ProtocolResp_Submit(ReqB113ProtocolSubmit query) throws Exception {
        return null;
    }
    @Override
    public RetAtsB119BillRelePledSubmit D_B119_BillResp_Submit(ReqB119BillRelePledSubmit query) throws Exception {
        return null;
    }

    /**
     * 提示收款人收票撤回 ok
     * @param query
     * @return
     * @throws Exception
     */
    private RetAtsB112BillCancSubmitDetail b112BillRespSubmitOne(ReqB112BillCancSubmit query) throws Exception{
        RetAtsB112BillCancSubmitDetail detail=new RetAtsB112BillCancSubmitDetail();
        //赋值通用参数
        serviceId = "srv3028_submitRecDraftCancel";
        XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象
        //写入通用的头部节点
        writeCommonHeader(xmlWriter);
        if(!"".equals(bankFront.token)) {
            //先根据票据号码查询票据详细信息
            XElement billInfo = getBillInfoByCancel(query.detail.actNum,query.detail.billNo.substring(0,1),
                    query.detail.billNo,"1");
            if( billInfo!=null){
                xmlWriter.writeElementString("functionId", "srv3028");
                xmlWriter.writeElementString("functionName", "提示收款人收票撤回");
                //请求报文体
                xmlWriter.writeStartElement("opReq");
                xmlWriter.writeElementString("serialNo", query.detail.reqSeqID);//交易序列号
                xmlWriter.writeElementString("reqTime", Format.Date8Format.format(new Date()));//客户端请求时间
                xmlWriter.writeStartElement("ReqParam");
                xmlWriter.writeElementString("BWBZH", billInfo.getSingleText("BWBZH"));//报文标志号
                xmlWriter.writeElementString("BWSJ", billInfo.getSingleText("BWSJ"));//报文时间
                xmlWriter.writeElementString("PJJE", billInfo.getSingleText("PJJE"));//票据金额
                //xmlWriter.writeElementString("DZQM", "");//电子签名
                xmlWriter.writeElementString("PJHM", billInfo.getSingleText("PJHM"));//票据号码
                xmlWriter.writeElementString("CPRZH", billInfo.getSingleText("CPRZH"));//出票人帐号
                xmlWriter.writeElementString("CPRHH", billInfo.getSingleText("CPRHH"));//出票人行号
                xmlWriter.writeElementString("KHHM", getBankConfig().getValueAsString("customerID"));//客户号码
                xmlWriter.writeElementString("PJZL", billInfo.getSingleText("PJZL"));//票据种类
                xmlWriter.writeElementString("ZRBJ", billInfo.getSingleText("ZRBJ"));//不得转让标志
                xmlWriter.writeElementString("PJZT", billInfo.getSingleText("PJZT"));//票据状态
                xmlWriter.writeElementString("CPRLB", billInfo.getSingleText("CPRLB"));//出票人类别
                xmlWriter.writeElementString("CPRMC", billInfo.getSingleText("CPRMC"));//出票人名称
                xmlWriter.writeElementString("CPRHM", billInfo.getSingleText("CPRHM"));//出票人行名
                //xmlWriter.writeElementString("JYLB", billInfo.getSingleText("JYLB"));//交易类别
                xmlWriter.writeElementString("SPRZH", billInfo.getSingleText("SPRZH"));//收票人账号
                xmlWriter.writeElementString("SPRMC", billInfo.getSingleText("SPRMC"));//收票人名称
                xmlWriter.writeElementString("SPRHH", billInfo.getSingleText("SPRHH"));//收票人行号
                xmlWriter.writeElementString("SPRHM", billInfo.getSingleText("SPRHM"));//收票人行名
                xmlWriter.writeElementString("CPRQ",billInfo.getSingleText("CPRQ"));//出票日期
                xmlWriter.writeElementString("DQR", billInfo.getSingleText("DQR"));//到期日
                xmlWriter.writeEndElement();
                xmlWriter.writeEndElement();
                String signXml = getDataSignData(xmlWriter);
                if (signnatrue(signXml) == true) {
                    xmlWriter.writeElementString("signData", signature);//签名数据
                    xmlWriter.writeEndDocument();
                    String[] tmpStrRet = sendToBank(getDataSendBank(xmlWriter.toXmlString()));//发送银行

                    if (tmpStrRet[0].length() == 0) {
                        StringBuilder tmpSbMsg2 = new StringBuilder();
                        XmlTextReader tmpBkReader2 = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg2);
                        if (tmpBkReader2 != null) {
                            String respCode = tmpBkReader2.getFirstText("/NBCBEBankData/retCode");
                            String respInfo = tmpBkReader2.getFirstText("/NBCBEBankData/errorMsg");
                            if (respCode != null && isActiveRetCode(respCode)) {
                                detail.respCode = "0";
                                detail.respInfo = tmpBkReader2.getFirstText("/NBCBEBankData/opRep/opResult/SBYY");
                                detail.reqSeqID = query.detail.reqSeqID;
                                detail.payInfoCode = tmpBkReader2.getFirstText("/NBCBEBankData/opRep/opResult/JYZT");
                                detail.transState = detail.payInfoCode;
                            }else {
                                detail.respCode = "0";
                                detail.respInfo = respCode+"："+respInfo;
                                detail.reqSeqID = query.detail.reqSeqID;
                                detail.payInfoCode = "91";//银行确认 返回非0000或非000000时，可以判定交易失败
                                detail.transState = detail.payInfoCode;
                            }
                        } else {
                            detail.respCode = "-1";
                            detail.respInfo = tmpSbMsg2.toString();
                        }
                    } else {
                        detail.respCode = "-1";
                        detail.respInfo = tmpStrRet[1];
                    }
                }else {
                    detail.respCode = "-1";
                    detail.respInfo = tmpSign[1];
                }
            }else {
                detail.respCode = "-1";
                detail.respInfo = "查询票据详情失败";
            }
        }else {
            detail.respCode = "-1";
            detail.respInfo = "登录失败";
        }
        return detail;
    }
    /**
     * 背书转让撤销  ok
     * @param query
     * @return
     * @throws Exception
     */
    private RetAtsB112BillCancSubmitDetail b112BillRespSubmitTwo(ReqB112BillCancSubmit query) throws Exception{
        RetAtsB112BillCancSubmitDetail detail=new RetAtsB112BillCancSubmitDetail();
        //赋值通用参数
        serviceId = "srv3011_submitEndorseCancel";
        XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象
        //写入通用的头部节点
        writeCommonHeader(xmlWriter);
        if(!"".equals(bankFront.token)) {
        XElement billInfo = getBillInfoByCancel(query.detail.actNum,query.detail.billNo.substring(0,1),
                query.detail.billNo,"2");
        if( billInfo!=null){
            xmlWriter.writeElementString("functionId", "srv3011");
                xmlWriter.writeElementString("functionName", "背书转让撤销");
                //请求报文体
                xmlWriter.writeStartElement("opReq");
                xmlWriter.writeElementString("serialNo", query.detail.reqSeqID);//交易序列号
                xmlWriter.writeElementString("reqTime", Format.Date8Format.format(new Date()));//客户端请求时间
                xmlWriter.writeStartElement("ReqParam");
                xmlWriter.writeElementString("PJZL", billInfo.getSingleText("PJZL"));//票据类型
                xmlWriter.writeElementString("KHHM", getBankConfig().getValueAsString("customerID"));//客户号码
                xmlWriter.writeElementString("PJHM", billInfo.getSingleText("PJHM"));//票据号码
                xmlWriter.writeElementString("PJJE", billInfo.getSingleText("PJJE"));//票据金额
                xmlWriter.writeElementString("PJZT", billInfo.getSingleText("PJZT"));//票据状态
                xmlWriter.writeElementString("ZRBJ", billInfo.getSingleText("ZRBJ"));//不得转让标志
                xmlWriter.writeElementString("BWBZH", billInfo.getSingleText("BWBZH"));//报文标志号
                xmlWriter.writeElementString("BWSJ",  billInfo.getSingleText("BWSJ"));//报文时间
                xmlWriter.writeElementString("CPRLB", billInfo.getSingleText("CPRLB"));//出票人类别
                xmlWriter.writeElementString("CPRMC", billInfo.getSingleText("CPRMC"));//出票人名称
                xmlWriter.writeElementString("CPRZH", billInfo.getSingleText("CPRZH"));//出票人帐号
                xmlWriter.writeElementString("CPRHH", billInfo.getSingleText("CPRHH"));//出票人行号
                xmlWriter.writeElementString("CPRHM", billInfo.getSingleText("CPRHM"));//出票人行名
                xmlWriter.writeElementString("JYLB", billInfo.getSingleText("JYLB"));//交易类别
                xmlWriter.writeElementString("SPRMC", billInfo.getSingleText("SPRMC"));//收票人名称
                xmlWriter.writeElementString("SPRZH", billInfo.getSingleText("SPRZH"));//收票人账号
                xmlWriter.writeElementString("SPRHH", billInfo.getSingleText("SPRHH"));//收票人行号
                xmlWriter.writeElementString("SPRHM", billInfo.getSingleText("SPRHM"));//收票人行名
                xmlWriter.writeElementString("DZQM", billInfo.getSingleText("DZQM"));//电子签名
                xmlWriter.writeElementString("CPRQ", billInfo.getSingleText("CPRQ"));//出票日期
                xmlWriter.writeElementString("DQR",  billInfo.getSingleText("DQR"));//到期日
                xmlWriter.writeEndElement();
                xmlWriter.writeEndElement();
                String signXml = getDataSignData(xmlWriter);
                if (signnatrue(signXml) == true) {
                    xmlWriter.writeElementString("signData", signature);//签名数据
                    xmlWriter.writeEndDocument();
                    String[] tmpStrRet = sendToBank(getDataSendBank(xmlWriter.toXmlString()));//发送银行

                    if (tmpStrRet[0].length() == 0) {
                        StringBuilder tmpSbMsg2 = new StringBuilder();
                        XmlTextReader tmpBkReader2 = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg2);
                        if (tmpBkReader2 != null) {
                            String respCode = tmpBkReader2.getFirstText("/NBCBEBankData/retCode");
                            String respInfo = tmpBkReader2.getFirstText("/NBCBEBankData/errorMsg");
                            if (respCode != null && isActiveRetCode(respCode)) {
                                detail.respCode = "0";
                                detail.respInfo = tmpBkReader2.getFirstText("/NBCBEBankData/opRep/opResult/SBYY");
                                detail.reqSeqID = query.detail.reqSeqID;
                                detail.payInfoCode = tmpBkReader2.getFirstText("/NBCBEBankData/opRep/opResult/JYZT");
                                detail.transState = detail.payInfoCode;
                            }else {
                                detail.respCode = "0";
                                detail.respInfo = respCode+"："+respInfo;
                                detail.reqSeqID = query.detail.reqSeqID;
                                detail.payInfoCode = "91";//银行确认 返回非0000或非000000时，可以判定交易失败
                                detail.transState = detail.payInfoCode;
                            }
                    }else {
                            detail.respCode = "-1";
                            detail.respInfo = tmpSbMsg2.toString();
                        }
                    }else {
                        detail.respCode = "-1";
                        detail.respInfo = tmpStrRet[1];
                    }
                }else {
                    detail.respCode = "-1";
                    detail.respInfo = tmpSign[1];
                }
            }else {
                detail.respCode = "-1";
                detail.respInfo = "查询票据详情失败";
            }
        }else {
            detail.respCode = "-1";
            detail.respInfo = "登录失败";
        }
        return detail;
    }
    /**
     * 提示付款撤回
     * @param query
     * @return
     * @throws Exception
     */
    private RetAtsB112BillCancSubmitDetail b112BillRespSubmitThree(ReqB112BillCancSubmit query) throws Exception{
        RetAtsB112BillCancSubmitDetail detail=new RetAtsB112BillCancSubmitDetail();
        //赋值通用参数
        serviceId = "srv3030_submitPayDraftCancel";
        XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象
        //写入通用的头部节点
        writeCommonHeader(xmlWriter);
        if(!"".equals(bankFront.token)) {
            //先根据票据号码查询票据详细信息
            XElement billInfo = getBillInfoByCancel(query.detail.actNum,query.detail.billNo.substring(0,1),
                    query.detail.billNo,"srv3030");

            xmlWriter.writeElementString("functionId", "srv3030");
            xmlWriter.writeElementString("functionName", "提示付款撤销");
            //请求报文体
            xmlWriter.writeStartElement("opReq");
            xmlWriter.writeElementString("serialNo", query.detail.reqSeqID);//交易序列号
            xmlWriter.writeElementString("reqTime", Format.Date8Format.format(new Date()));//客户端请求时间
            xmlWriter.writeStartElement("ReqParam");
            xmlWriter.writeElementString("KHHM", getBankConfig().getValueAsString("customerID"));//客户号码
            xmlWriter.writeElementString("CPRZH", query.detail.billOpenAcc);//出票人帐号
            xmlWriter.writeElementString("CPRMC", query.detail.billOpenName);//出票人名称
            xmlWriter.writeElementString("CPRLB", billInfo.getSingleText("CPRLB"));//出票人类别
            xmlWriter.writeElementString("CPRHM", billInfo.getSingleText("CPRHM"));//出票人行名
            xmlWriter.writeElementString("CPRCJHH",billInfo.getSingleText("CPRCJHH"));//出票人承接行号
            xmlWriter.writeElementString("CPRHH",billInfo.getSingleText("CPRHH"));//出票人行号
            xmlWriter.writeElementString("CPRJGDM",billInfo.getSingleText("CPRJGDM"));//出票人机构代码
            xmlWriter.writeElementString("BEIZ", billInfo.getSingleText("BEIZ"));//备注
            xmlWriter.writeElementString("BEIZ1", billInfo.getSingleText("BEIZ1"));//备注1
            xmlWriter.writeElementString("PJJE", query.detail.billAmt);//票据金额
            xmlWriter.writeElementString("PJHM", query.detail.billNo);//票据号码
            xmlWriter.writeElementString("PJLX", billInfo.getSingleText("PJZL"));//票据类型
            xmlWriter.writeElementString("PJZT", billInfo.getSingleText("PJZT"));//票据状态
            xmlWriter.writeElementString("JYJE", billInfo.getSingleText("FKJE"));//交易金额
            xmlWriter.writeElementString("CPQR", billInfo.getSingleText("CPRQ"));//出票日期
            xmlWriter.writeElementString("QSBJ", billInfo.getSingleText("QSBZ"));//线上清算标记
            xmlWriter.writeElementString("SPRJGDM", billInfo.getSingleText("SPRJGDM"));//收票人机构代码
            xmlWriter.writeElementString("HFBJ", billInfo.getSingleText("HFBJ"));//回复标记
            xmlWriter.writeElementString("JLZT", billInfo.getSingleText("JLZT"));//记录状态
            xmlWriter.writeElementString("SPRZH", billInfo.getSingleText("SPRZH"));//收票人账号
            xmlWriter.writeElementString("SPRHH", billInfo.getSingleText("SPRHH"));//收票人行号
            xmlWriter.writeElementString("SPRHM", billInfo.getSingleText("SPRHM"));//收票人行名
            xmlWriter.writeElementString("SPRCJHH", billInfo.getSingleText("SPRCJHH"));//收票人承接行号
            xmlWriter.writeElementString("QSBWBZ", billInfo.getSingleText("QSBWBZ"));//报文标志
            xmlWriter.writeElementString("SPRMC", billInfo.getSingleText("SPRMC"));//收票人名称
            xmlWriter.writeElementString("BWSJ", billInfo.getSingleText("BWSJ"));//报文时间
            xmlWriter.writeElementString("SPRLB", billInfo.getSingleText("SPRLB"));//收票人类别
            xmlWriter.writeElementString("SQRQ", billInfo.getSingleText("SQRQ"));//申请日期
            xmlWriter.writeElementString("TSFKRLB", billInfo.getSingleText("TSFKRLB"));//申请人类别
            xmlWriter.writeElementString("TSFKRMC", billInfo.getSingleText("TSFKRMC"));//申请人名称
            xmlWriter.writeElementString("TSFKRZH", billInfo.getSingleText("TSFKRZH"));//申请人账号
            xmlWriter.writeElementString("TSFKRHM", billInfo.getSingleText("TSFKRHM"));//申请人行名
            xmlWriter.writeElementString("TSFKRHH", billInfo.getSingleText("TSFKRHH"));//申请人行号
            xmlWriter.writeElementString("TSFKRCJHH", billInfo.getSingleText("TSFKRCJHH"));//申请人承接行号
            xmlWriter.writeElementString("TSFKRDM", billInfo.getSingleText("TSFKRDM"));//申请人组织机构代码

            xmlWriter.writeElementString("FKRLB", billInfo.getSingleText("FKRLB"));//付款人类别
            xmlWriter.writeElementString("FKRJGDM", billInfo.getSingleText("TSFKRDM"));//付款人机构代码
            xmlWriter.writeElementString("FKRMC", billInfo.getSingleText("FKRMC"));//付款人名称
            xmlWriter.writeElementString("FKRZH", billInfo.getSingleText("FKRZH"));//付款人帐号
            xmlWriter.writeElementString("FKRCJHH", billInfo.getSingleText("FKRCJHH"));//付款人承接行号
            xmlWriter.writeElementString("FKRHH", billInfo.getSingleText("FKRHH"));//付款人行号
            xmlWriter.writeElementString("FKRHM", billInfo.getSingleText("FKRHM"));//付款人行名

            xmlWriter.writeElementString("QSBWBZ", billInfo.getSingleText("QSBWBZ"));//签收报文标识号
            xmlWriter.writeElementString("SJLY", billInfo.getSingleText("SJLY"));//数据来源
            xmlWriter.writeElementString("BWBZH", billInfo.getSingleText("BWBZ"));//报文标志号
            xmlWriter.writeElementString("CPRQ", billInfo.getSingleText("CPRQ"));//出票日期
            xmlWriter.writeElementString("DQRQ", billInfo.getSingleText("DQR"));//到期日
            xmlWriter.writeElementString("ZRBJ", billInfo.getSingleText("ZRBJ"));//不得转让标志
            xmlWriter.writeElementString("JFDM", billInfo.getSingleText("JFDM"));//拒绝代码
            xmlWriter.writeElementString("CPRZZH", billInfo.getSingleText("CPRZZH"));//出票人子账号
            xmlWriter.writeElementString("QRBZ", billInfo.getSingleText("QRBZ"));//确认标志
            xmlWriter.writeElementString("CXTJ", "");//查询条件
            xmlWriter.writeElementString("YQYY", billInfo.getSingleText("YQYY"));//逾期原因
            xmlWriter.writeElementString("HFRQ", billInfo.getSingleText("HFRQ"));//回复日期
            xmlWriter.writeEndElement();
            xmlWriter.writeEndElement();
            String signXml = getDataSignData(xmlWriter);
            if (signnatrue(signXml) == true) {
                xmlWriter.writeElementString("signData", signature);//签名数据
                xmlWriter.writeEndDocument();
                String[] tmpStrRet = sendToBank(getDataSendBank(xmlWriter.toXmlString()));//发送银行

                if (tmpStrRet[0].length() == 0) {
                    StringBuilder tmpSbMsg2 = new StringBuilder();
                    XmlTextReader tmpBkReader2 = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg2);
                    if (tmpBkReader2 != null) {
                        String respCode = tmpBkReader2.getFirstText("/NBCBEBankData/retCode");
                        String respInfo = tmpBkReader2.getFirstText("/NBCBEBankData/errorMsg");
                        if (respCode != null && isActiveRetCode(respCode)) {
                            detail.respCode = "0";
                            detail.respInfo = tmpBkReader2.getFirstText("/NBCBEBankData/opRep/opResult/SBYY");
                            detail.reqSeqID = query.detail.reqSeqID;
                            detail.payInfoCode = tmpBkReader2.getFirstText("/NBCBEBankData/opRep/opResult/JYZT");
                            detail.transState = detail.payInfoCode;
                        }else {
                            detail.respCode = "0";
                            detail.respInfo = respCode+"："+respInfo;
                            detail.reqSeqID = query.detail.reqSeqID;
                            detail.payInfoCode = "91";//银行确认 返回非0000或非000000时，可以判定交易失败
                            detail.transState = detail.payInfoCode;
                        }
                    } else {
                        detail.respCode = "-1";
                        detail.respInfo = tmpSbMsg2.toString();
                    }
                } else {
                    detail.respCode = "-1";
                    detail.respInfo = tmpStrRet[1];
                }
            }else {
                detail.respCode = "-1";
                detail.respInfo = tmpSign[1];
            }
        }else {
            detail.respCode = "-1";
            detail.respInfo = "登录失败";
        }
        return detail;
    }

    /**
     * 银承出票
     * @param query
     * @return
     * @throws Exception
     */
    private RetAtsB101BillApplySubmitDetail b101BillRespSubitOne (ReqB101BillApplySubmit query)throws Exception{
        RetAtsB101BillApplySubmitDetail detail=new RetAtsB101BillApplySubmitDetail();
        //赋值通用参数
        serviceId = "srv157_billApply";
        XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象
        //写入通用的头部节点
        writeCommonHeader(xmlWriter);
        if(!"".equals(bankFront.token)) {
            //while (query.readRecord()) {
                //查询保证金过度户
                String[] marginDetails=getMarginAccount(bankFront.corpNo,bankFront.org);
                String[] accountNo=new String[]{"",""};
                if("".equals(marginDetails[0])) {
                    //新开保证金户
                    accountNo=newMarginAccount(query.detail.billAmt,query.detail.drawAct);
                }else {
                    accountNo=marginDetails;
                }
                if(!"".equals(accountNo[0])) {
                    xmlWriter.writeElementString("functionId", "srv157");
                    xmlWriter.writeElementString("functionName", "电子银行承兑汇票申请");
                    //请求报文体
                    xmlWriter.writeStartElement("opReq");
                    xmlWriter.writeElementString("serialNo", query.detail.reqSeqID);//交易序列号
                    xmlWriter.writeElementString("reqTime", Format.Date8Format.format(new Date()));//客户端请求时间
                    xmlWriter.writeStartElement("ReqParam");
                    xmlWriter.writeElementString("SQBZ", "01");//申请币种 01人民币
                    xmlWriter.writeElementString("SQJE", query.detail.billAmt);//申请总额
                    xmlWriter.writeElementString("BZJBZ", "01");//保证金币种 01人民币
                    String bailRate=(new BigDecimal(query.detail.billAmt).subtract(new BigDecimal(query.detail.useCreditAmount)))
                            .multiply(new BigDecimal("100")).divide(new BigDecimal(query.detail.billAmt),2,BigDecimal.ROUND_HALF_UP).toString();
                    xmlWriter.writeElementString("BZJBL", bailRate);//保证金比例
                    xmlWriter.writeElementString("KHHM", getBankConfig().getValueAsString("customerID"));//实际交易客户号
                    xmlWriter.writeElementString("CPRZH", query.detail.drawAct);//出票账号
                    xmlWriter.writeElementClosed("CPRHH");//承兑行行号
                    xmlWriter.writeElementString("PJLX", "107");//票据类型
                    xmlWriter.writeElementString("BEIZ", query.detail.memo);//备注
                    xmlWriter.writeElementString("SFZTC", "2");//是否直通车 2否
                    xmlWriter.writeElementString("SFYJSP", "2");//是否一键出票 2否
                    xmlWriter.writeElementString("HDBZ", "1");//保证金活定期标志 1 定期 2活期
                    xmlWriter.writeElementString("BZJZH", accountNo[0]);//保证金账号
                    xmlWriter.writeElementString("BZJFZH", accountNo[1]);//保证金分账号
                    xmlWriter.writeElementString("SXFZH", query.detail.drawAct);//手续费账号
                    xmlWriter.writeElementClosed("SXFFZH");//手续费分账号
                    xmlWriter.writeElementString("YJDZ", getBankConfig().getMapAdvanceValue("DrawInfo","key","addr",query.detail.drawAct));//邮寄地址
                    xmlWriter.writeElementString("SJRMC", getBankConfig().getMapAdvanceValue("DrawInfo","key","name",query.detail.drawAct));//收件人名称
                    xmlWriter.writeElementString("ZIWU", getBankConfig().getMapAdvanceValue("DrawInfo","key","job",query.detail.drawAct));//职务
                    xmlWriter.writeElementClosed("SFZH");//身份证号码
                    xmlWriter.writeElementString("LXDH", getBankConfig().getMapAdvanceValue("DrawInfo","key","tele",query.detail.drawAct));//联系电话
                    xmlWriter.writeElementClosed("CZHM");//传真
                    xmlWriter.writeElementClosed("SJHM");//手机号码
                    xmlWriter.writeElementClosed("DZYX");//电子邮箱
                    xmlWriter.writeElementString("XYBZ","2");
                    xmlWriter.writeElementClosed("CDXYH");
                    xmlWriter.writeElementString("CKCDF","0");
                    xmlWriter.writeStartElement("list");
                    xmlWriter.writeStartElement("row");
                    xmlWriter.writeElementString("SKRZH", query.detail.payeeAct);//收票人账号
                    xmlWriter.writeElementString("SKRMC", query.detail.payeeName);//收票人名称
                    xmlWriter.writeElementString("SKRHM", query.detail.payeeBnkName);//收票人行名
                    xmlWriter.writeElementString("SKRHH", query.detail.payeeBnkCode);//收票人行号
                    xmlWriter.writeElementString("JYJE", query.detail.billAmt);//金额
                    int month=timeDifference(query.detail.issDate,query.detail.dueDate);
                    xmlWriter.writeElementString("QXS", month+"");//期限
                    xmlWriter.writeElementString("ZRBJ", getBankConfig().getMapValueByKey("transFlagMapping",query.detail.transFlag));//转让标志
                    xmlWriter.writeElementString("SFZDTX", "2");//是否自动提示收票 否
                    xmlWriter.writeElementString("SFKXQX", "2");//是否可选期限 否
                    xmlWriter.writeEndElement();
                    xmlWriter.writeEndElement();
                    xmlWriter.writeEndElement();
                    xmlWriter.writeEndElement();
                    String signXml = getDataSignData(xmlWriter);
                    if (signnatrue(signXml) == true) {
                        xmlWriter.writeElementString("signData", signature);//签名数据
                        xmlWriter.writeEndDocument();
                        String[] tmpStrRet = sendToBank(getDataSendBank(xmlWriter.toXmlString()));//发送银行

                        if (tmpStrRet[0].length() == 0) {
                            StringBuilder tmpSbMsg2 = new StringBuilder();
                            XmlTextReader tmpBkReader2 = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg2);
                            if (tmpBkReader2 != null) {
                                String respCode = tmpBkReader2.getFirstText("/NBCBEBankData/retCode");
                                String respInfo = tmpBkReader2.getFirstText("/NBCBEBankData/errorMsg");
                                if (respCode != null && isActiveRetCode(respCode)) {
                                    detail.respCode = "0";
                                    detail.respInfo = tmpBkReader2.getFirstText("/NBCBEBankData/opRep/opResult/SBYY");
                                    detail.reqSeqID = tmpBkReader2.getFirstText("/NBCBEBankData/opRep/opResult/ZLLS");
                                    detail.payInfoCode = tmpBkReader2.getFirstText("/NBCBEBankData/opRep/opResult/JYZT");
                                    detail.transState = detail.payInfoCode;
                                }else {
                                    detail.respCode = "0";
                                    detail.respInfo = respCode+"："+respInfo;
                                    detail.reqSeqID = query.detail.reqSeqID;
                                    detail.payInfoCode = "91";//银行确认 返回非0000或非000000时，可以判定交易失败
                                    detail.transState = detail.payInfoCode;
                                }
                            } else {
                                detail.respCode = "-1";
                                detail.respInfo = tmpSbMsg2.toString();
                            }
                        } else {
                            detail.respCode = "-1";
                            detail.respInfo = tmpStrRet[1];
                        }
                    }else {
                        detail.respCode = "-1";
                        detail.respInfo = tmpSign[1];
                    }
                }else {
                    detail.respCode = "-1";
                    detail.respInfo = "查询保证金账户失败";
                }
            //}
        }else {
            detail.respCode = "-1";
            detail.respInfo = "登录失败";
        }
        return detail;
    }

    /**
     * 商承出票
     * @param query
     * @return
     * @throws Exception
     */
    private RetAtsB101BillApplySubmitDetail b101BillRespSubitTwo (ReqB101BillApplySubmit query) throws Exception{
        RetAtsB101BillApplySubmitDetail detail=new RetAtsB101BillApplySubmitDetail();
        //赋值通用参数
        serviceId = "srv170_ticketInfoApply";
        XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象
        //写入通用的头部节点
        writeCommonHeader(xmlWriter);
        if(!"".equals(bankFront.token)) {
            //while (query.readRecord()) {
                xmlWriter.writeElementString("functionId", "srv170");
                xmlWriter.writeElementString("functionName", "电子商业承兑汇票提示出票申请");
                //请求报文体
                xmlWriter.writeStartElement("opReq");
                xmlWriter.writeElementString("serialNo", getQryTransID());//交易序列号
                xmlWriter.writeElementString("reqTime", Format.Date8Format.format(new Date()));//客户端请求时间
                xmlWriter.writeStartElement("ReqParam");
                xmlWriter.writeElementString("FKZH", query.detail.drawAct);//出票账号
                xmlWriter.writeElementString("KHHM", getBankConfig().getValueAsString("customerID"));//交易客户号
                xmlWriter.writeStartElement("list");
                xmlWriter.writeStartElement("row");
                xmlWriter.writeElementString("DQRQ", query.detail.dueDate.substring(0,10).replace("-",""));//到期日
                xmlWriter.writeElementString("PJJE", query.detail.billAmt);//票据金额
                xmlWriter.writeElementString("CDRZH", query.detail.accpAct);//承兑人账号
                xmlWriter.writeElementString("CDRMC", query.detail.accpName);//承兑人名称
                xmlWriter.writeElementString("CDRHH", query.detail.accpBnkCode);//承兑人行号
                xmlWriter.writeElementString("CDRHM", query.detail.accpBnkName);//承兑人行名
                xmlWriter.writeElementString("SPRZH", query.detail.payeeAct);//收票人账号
                xmlWriter.writeElementString("SPRMC", query.detail.payeeName);//收票人名称
                xmlWriter.writeElementString("SPRHH", query.detail.payeeBnkCode);//收票人行号
                xmlWriter.writeElementString("SPRHM", query.detail.payeeBnkName);//收票人行名
                xmlWriter.writeElementString("ZRBJ", getBankConfig().getMapValueByKey("transFlagMapping",query.detail.transFlag));//不得转让标志
                xmlWriter.writeEndDocument();
                String signXml = getDataSignData(xmlWriter);
                if (signnatrue(signXml) == true) {
                    xmlWriter.writeElementString("signData", signature);//签名数据
                    xmlWriter.writeEndDocument();
                    String[] tmpStrRet = sendToBank(getDataSendBank(xmlWriter.toXmlString()));//发送银行
                    if (tmpStrRet[0].length() == 0) {
                        StringBuilder tmpSbMsg2 = new StringBuilder();
                        XmlTextReader tmpBkReader2 = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg2);
                        if (tmpBkReader2 != null) {
                            String respCode = tmpBkReader2.getFirstText("/NBCBEBankData/retCode");
                            String respInfo = tmpBkReader2.getFirstText("/NBCBEBankData/errorMsg");
                            if (respCode != null && isActiveRetCode(respCode)) {
                                detail.respCode = "0";
                                detail.respInfo = tmpBkReader2.getFirstText("/NBCBEBankData/opRep/opResult/SBYY");
                                detail.reqSeqID = tmpBkReader2.getFirstText("/NBCBEBankData/opRep/opResult/ZLLS");
                                detail.payInfoCode = tmpBkReader2.getFirstText("/NBCBEBankData/opRep/opResult/JYZT");
                                detail.transState = detail.payInfoCode;
                            }else {
                                detail.respCode = "0";
                                detail.respInfo = respCode+"："+respInfo;
                                detail.reqSeqID = query.detail.reqSeqID;
                                detail.payInfoCode = "91";//银行确认 返回非0000或非000000时，可以判定交易失败
                                detail.transState = detail.payInfoCode;
                            }
                        } else {
                            detail.respCode = "-1";
                            detail.respInfo = tmpSbMsg2.toString();
                        }
                    } else {
                        detail.respCode = "-1";
                        detail.respInfo = tmpStrRet[1];
                    }
                }else {
                    detail.respCode = "-1";
                    detail.respInfo = tmpSign[1];
                }
            //}
        }else {
            detail.respCode = "-1";
            detail.respInfo = "登录失败";
        }
        return detail;
    }

    /**
     * 银承提示承兑
     * @param query
     * @return
     * @throws Exception
     */
    private RetAtsB102BillAccpSubmitDetail b102BillRespSubitOne (ReqB102BillAccpSubmit query) throws Exception{
        RetAtsB102BillAccpSubmitDetail detail=new RetAtsB102BillAccpSubmitDetail();
        //赋值通用参数
        serviceId = "srv160_sendBillAcceptBillInfo";
        XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象
        //写入通用的头部节点
        writeCommonHeader(xmlWriter);
        if(!"".equals(bankFront.token)) {
                xmlWriter.writeElementString("functionId", "srv160");
                xmlWriter.writeElementString("functionName", "银票出票承兑申请");
                //请求报文体
                xmlWriter.writeStartElement("opReq");
                xmlWriter.writeElementString("serialNo", getQryTransID());//交易序列号
                xmlWriter.writeElementString("reqTime", Format.Date8Format.format(new Date()));//客户端请求时间
                xmlWriter.writeStartElement("ReqParam");
                xmlWriter.writeElementString("PJPCH", query.detail.reqSeqID);//申请批次号
                xmlWriter.writeElementString("KHHM", getBankConfig().getValueAsString("customerID"));//交易客户号
                xmlWriter.writeElementString("CPZH", query.detail.actNum);//出票账号
                xmlWriter.writeElementString("SQJE", query.detail.billAmt);//申请金额
                String pjxq=query.detail.reqSeqID+"|"+1+"|"+("1".equals(query.detail.transFlag)?"01":"02")+"|"
                        +query.detail.issDate.substring(0,10).replaceAll("-","")+"|"
                        +query.detail.dueDate.substring(0,10).replaceAll("-","")+"|"+query.detail.billAmt+"|";
                xmlWriter.writeElementString("PJXQ", pjxq.trim());//票据详情
                xmlWriter.writeElementString("SQBZ", "01");//币种
                xmlWriter.writeEndElement();
                xmlWriter.writeEndElement();
                String signXml = getDataSignData(xmlWriter);
                if (signnatrue(signXml) == true) {
                    xmlWriter.writeElementString("signData", signature);//签名数据
                    xmlWriter.writeEndDocument();
                    String[] tmpStrRet = sendToBank(getDataSendBank(xmlWriter.toXmlString()));//发送银行

                    if (tmpStrRet[0].length() == 0) {
                        StringBuilder tmpSbMsg2 = new StringBuilder();
                        XmlTextReader tmpBkReader2 = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg2);
                        if (tmpBkReader2 != null) {
                            String respCode = tmpBkReader2.getFirstText("/NBCBEBankData/retCode");
                            String respInfo = tmpBkReader2.getFirstText("/NBCBEBankData/errorMsg");
                            if (respCode != null && isActiveRetCode(respCode)) {
                                detail.respCode = "0";
                                detail.respInfo = tmpBkReader2.getFirstText("/NBCBEBankData/opRep/opResult/SBYY");
                                detail.reqSeqID = tmpBkReader2.getFirstText("/NBCBEBankData/opRep/opResult/ZLLS");
                                detail.payInfoCode = tmpBkReader2.getFirstText("/NBCBEBankData/opRep/opResult/JYZT");
                                detail.transState = detail.payInfoCode;
                            }else {
                                detail.respCode = "0";
                                detail.respInfo = respCode+"："+respInfo;
                                detail.reqSeqID = query.detail.reqSeqID;
                                detail.payInfoCode = "91";//银行确认 返回非0000或非000000时，可以判定交易失败
                                detail.transState = detail.payInfoCode;
                            }
                        } else {
                            detail.respCode = "-1";
                            detail.respInfo = tmpSbMsg2.toString();
                        }
                    } else {
                        detail.respCode = "-1";
                        detail.respInfo = tmpStrRet[1];
                    }
                }else {
                    detail.respCode = "-1";
                    detail.respInfo = tmpSign[1];
                }
        }else {
            detail.respCode = "-1";
            detail.respInfo = "登录失败";
        }
        return detail;
    }

    /**
     * 商承提示承兑
     * @param query
     * @return
     * @throws Exception
     */
    private RetAtsB102BillAccpSubmitDetail b102BillRespSubitTwo (ReqB102BillAccpSubmit query) throws Exception{
        RetAtsB102BillAccpSubmitDetail detail=new RetAtsB102BillAccpSubmitDetail();
        //赋值通用参数
        serviceId = "srv171_remindAccApply";
        XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象
        //写入通用的头部节点
        XElement billInfo = getBillInfoByOpen(query.detail.actNum,query.detail.billType,query.detail.billNo,"2");
        writeCommonHeader(xmlWriter);
        if(!"".equals(bankFront.token)) {
            xmlWriter.writeElementString("functionId", "srv171");
            xmlWriter.writeElementString("functionName", "电子商业承兑汇票提示承兑");
            //请求报文体
            xmlWriter.writeStartElement("opReq");
            xmlWriter.writeElementString("serialNo", getQryTransID());//交易序列号
            xmlWriter.writeElementString("reqTime", Format.Date8Format.format(new Date()));//客户端请求时间
            xmlWriter.writeStartElement("ReqParam");
//            KHHM	交易客户号		Y（必输域）
            xmlWriter.writeElementString("KHHM",getBankConfig().getValueAsString("customerID"));
//            PJJE	票据金额		Y（必输域）
            xmlWriter.writeElementString("PJJE",billInfo.getSingleText("PJJE"));
//            PJZT	票据状态		Y（必输域）
            xmlWriter.writeElementString("PJZT",billInfo.getSingleText("PJZT"));
//            PJHM	票据号码		Y（必输域）
            xmlWriter.writeElementString("PJHM",billInfo.getSingleText("PJHM"));
//            PJLX	票据类型		Y（必输域）
            xmlWriter.writeElementString("PJLX",billInfo.getSingleText("PJLX"));
//            ZRBJ	不得转让标志		Y（必输域）
            xmlWriter.writeElementString("ZRBJ",billInfo.getSingleText("ZRBJ"));
//            CPRMC	出票人名称		Y（必输域）
            xmlWriter.writeElementString("CPRMC",billInfo.getSingleText("CPRMC"));
//            CPRHM	出票人行名		Y（必输域）
            xmlWriter.writeElementString("CPRHM",billInfo.getSingleText("CPRHM"));
//            CPRHH	出票人行号		Y（必输域）
            xmlWriter.writeElementString("CPRHH",billInfo.getSingleText("CPRHH"));
//            CPRZH	出票人账号		Y（必输域）
            xmlWriter.writeElementString("CPRZH",billInfo.getSingleText("CPRZH"));
//            SPRZH	收票人账号		Y（必输域）
            xmlWriter.writeElementString("SPRZH",billInfo.getSingleText("SPRZH"));
//            SPRMC	收票人名称		Y（必输域）
            xmlWriter.writeElementString("SPRMC",billInfo.getSingleText("SPRMC"));
//            SPRHM	收票人行名		Y（必输域）
            xmlWriter.writeElementString("SPRHM",billInfo.getSingleText("SPRHM"));
//            SPRHH	收票人行号		Y（必输域）
            xmlWriter.writeElementString("SPRHH",billInfo.getSingleText("SPRHH"));
//            CDRMC	承兑人名称		Y（必输域）
            xmlWriter.writeElementString("CDRMC",billInfo.getSingleText("CDRMC"));
//            CDRZH	承兑人账号		Y（必输域）
            xmlWriter.writeElementString("CDRZH",billInfo.getSingleText("CDRZH"));
//            CDRHM	承兑人行名		Y（必输域）
            xmlWriter.writeElementString("CDRHM",billInfo.getSingleText("CDRHM"));
//            CDRHH	承兑人行号		Y（必输域）
            xmlWriter.writeElementString("CDRHH",billInfo.getSingleText("CDRHH"));
//            CPRQ	出票日期		Y（必输域）
            xmlWriter.writeElementString("CPRQ",billInfo.getSingleText("CPRQ"));
//            DQR	到期日		Y（必输域）
            xmlWriter.writeElementString("DQR",billInfo.getSingleText("DQR"));
//            CZH	出账号		Y（必输域）
            xmlWriter.writeElementString("CZH",billInfo.getSingleText("CZH"));
//            CZXH	出账序号		Y（必输域）
            xmlWriter.writeElementString("KHHM",billInfo.getSingleText("CZXH"));
//            CPRZZH	出票人子账号
            xmlWriter.writeElementString("CPRZZH",billInfo.getSingleText("CPRFZH"));
//            CDXY	承兑协议号
            xmlWriter.writeElementString("CDXY",billInfo.getSingleText("CDXY"));
//            JYHT	交易合同号
            xmlWriter.writeElementString("JYHT",billInfo.getSingleText("JYHT"));
//            FPHM	发票号码
            xmlWriter.writeElementString("FPHM",billInfo.getSingleText("FPHM"));
//            BZJBL	保证金比例		Y（必输域）	0
            xmlWriter.writeElementString("BZJBL",billInfo.getSingleText("BZJBL"));
            xmlWriter.writeEndElement();
            xmlWriter.writeEndElement();
            String signXml = getDataSignData(xmlWriter);
            if (signnatrue(signXml) == true) {
                xmlWriter.writeElementString("signData", signature);//签名数据
                xmlWriter.writeEndDocument();
                String[] tmpStrRet = sendToBank(getDataSendBank(xmlWriter.toXmlString()));//发送银行

                if (tmpStrRet[0].length() == 0) {
                    StringBuilder tmpSbMsg2 = new StringBuilder();
                    XmlTextReader tmpBkReader2 = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg2);
                    if (tmpBkReader2 != null) {
                        String respCode = tmpBkReader2.getFirstText("/NBCBEBankData/retCode");
                        String respInfo = tmpBkReader2.getFirstText("/NBCBEBankData/errorMsg");
                        if (respCode != null && isActiveRetCode(respCode)) {
                            detail.respCode = "0";
                            detail.respInfo = tmpBkReader2.getFirstText("/NBCBEBankData/opRep/opResult/SBYY");
                            detail.reqSeqID = tmpBkReader2.getFirstText("/NBCBEBankData/opRep/opResult/ZLLS");
                            detail.payInfoCode = tmpBkReader2.getFirstText("/NBCBEBankData/opRep/opResult/JYZT");
                            detail.transState = detail.payInfoCode;
                        }else {
                            detail.respCode = "0";
                            detail.respInfo = respCode+"："+respInfo;
                            detail.reqSeqID = query.detail.reqSeqID;
                            detail.payInfoCode = "91";//银行确认 返回非0000或非000000时，可以判定交易失败
                            detail.transState = detail.payInfoCode;
                        }
                    } else {
                        detail.respCode = "-1";
                        detail.respInfo = tmpSbMsg2.toString();
                    }
                } else {
                    detail.respCode = "-1";
                    detail.respInfo = tmpStrRet[1];
                }
            }else {
                detail.respCode = "-1";
                detail.respInfo = tmpSign[1];
            }
        }else {
            detail.respCode = "-1";
            detail.respInfo = "登录失败";
        }
        return detail;
    }
}
